package inter_demo

import "fmt"

type DbCommon interface {
	Insert(string) error
	Update(string) error
	Delete(string) error
}

type DbConfig struct {
	Host     string
	Port     string
	Username string
	Password string
	Database string
}

type MySql struct {
	config  DbConfig
	charset string
}

func (m MySql) Insert(data string) error {
	fmt.Println("mysql insert:", data)
	return nil
}

func (m MySql) Update(data string) error {
	fmt.Println("mysql update:", data)
	return nil
}

func (m MySql) Delete(data string) error {
	fmt.Println("mysql delete:", data)
	return nil
}

type PostgreSql struct {
	config  DbConfig
	charset string
}

func (m PostgreSql) Insert(data string) error {
	fmt.Println("PostgreSql insert:", data)
	return nil
}

func (m PostgreSql) Update(data string) error {
	fmt.Println("PostgreSql update:", data)
	return nil
}

func (m PostgreSql) Delete(data string) error {
	fmt.Println("PostgreSql delete:", data)
	return nil
}

func DemoR() {
	config := DbConfig{"127.0.0.1", "3306", "admin", "123", "cotton"}
	var db DbCommon = PostgreSql{config, "utf-8"}
	err := db.Insert("aa")
	if err != nil {
		panic(err)
	}
	db.Update("aa")
	db.Delete("aa")
}

// EmptyInterface 定义空接口类型
type EmptyInterface interface{}

func EmptyDemo() {
	//使用空接口类型的变量
	var e EmptyInterface
	s1 := "123"
	i1 := 11
	e = s1
	e = i1
	fmt.Println(e)

	//直接定义一个空接口变量
	var e2 interface{}
	e2 = s1
	fmt.Println(e2)

	//直接定义一个空接口变量
	var e3 any
	e3 = s1
	fmt.Println(e3)

	//value为空接口类型的map
	m := make(map[string]interface{})
	m["a"] = 123
	m["b"] = "010-123455"
	fmt.Println(m)
}
